package com.it.myd.bean.box;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Random;

public class UNOCard {
    private static final String[] icons = new String[]{"&#xe6c2;","&#xe748;","&#xe67b;","&#xe6b1;"};
    private static final String[] colors = new String[]{"#000000","#ff0000","#ffff00","#0000ff"};
    private static final String[] colors1 = new String[]{"黑月","红日","黄星","蓝雪"};
    private String C_icon1;
    private String C_icon2;
    private String C_icon3;
    private String C_icon4;
    private String C_count1;
    private String C_count2;
    private String C_color1;
    private String C_color2;
    private String C_color3;
    private String C_color4;
    private String C_color5;
    private String C_type;
    private String C_content;
    private String C_canout;
    private String C_fields;
    private String C_json;

    public UNOCard() {
        Random random = new Random();
        int randomcount = random.nextInt(10)+1;
        int randomcount1 = random.nextInt(10)+1;
        int randomcount2 = random.nextInt(10)+1;
        if(randomcount < 9) {
            if (randomcount1 > 8) {
                addtwoUno();
            }else if(randomcount1 > 7 && randomcount1 <= 8){
                reversalUno();
            }else if(randomcount1 > 6 && randomcount1 <= 7){
                stopUno();
            }else {
                baseUno();
            }
        }else{
            if (randomcount1 > 6) {
                if(randomcount1 > 6){
                    alloutaddtwoUno();
                }
            }else if(randomcount1 > 2 && randomcount1 <= 6){
                alloutchangeUno();
            }else {
                if(randomcount2 > 2){
                    alloutaddfourUno();
                }else{
                    alloutUno();
                }
            }
        }
        setjson();
    }

    private void baseUno(){
        C_type = "baseUno";
        Random random = new Random();
        int count = random.nextInt(8)+1;
        int icon = random.nextInt(4);
        C_icon1 = icons[icon];
        C_color1 = colors[icon];
        C_color2 = colors1[icon];
        C_count1 = String.valueOf(count);
        C_canout = "无,"+C_color1 + "," + C_count1;
        C_fields = "UNO,"+C_color1 + "," + C_count1;
        C_content  = C_color2 + " - " + C_count1;
    }
    private void reversalUno(){
        C_type = "reversalUno";
        Random random = new Random();
        int icon = random.nextInt(4);
        C_icon1 = icons[icon];
        C_color1 = colors[icon];
        C_color2 = colors1[icon];
        C_count1 = "-1";
        C_canout = "无,"+C_color1 + "," + C_count1;
        C_fields = "UNO,"+C_color1 + "," + C_count1;
        C_content  = C_color2 + " - 反转";
    }

    private void stopUno(){
        C_type = "stopUno";
        Random random = new Random();
        int icon = random.nextInt(4);
        C_icon1 = icons[icon];
        C_color1 = colors[icon];
        C_color2 = colors1[icon];
        C_count1 = "-2";
        C_canout = "无,"+C_color1 + "," + C_count1;
        C_fields = "UNO,"+C_color1 + "," + C_count1;
        C_content  = C_color2 + " - 停止";
    }
    private void alloutUno(){
        C_type = "alloutUno";
        C_color1 = "#";
        C_count1 = "0";
        C_canout = "UNO,无";
        C_fields = "无";
        C_content  = "万能卡";
    }
    private void addtwoUno(){
        C_type = "addtwoUno";
        Random random = new Random();
        int icon = random.nextInt(4);
        C_icon1 = icons[icon];
        C_color1 = colors[icon];
        C_color2 = colors1[icon];
        C_count1 = "10";
        C_canout = "无,"+C_color1 + ",+2";
        C_fields = "UNO,"+C_color1 + ",+2";
        C_content  = C_color2 + " - +2";
    }
    private void alloutaddfourUno(){
        C_type = "alloutaddfourUno";
        C_color1 = "#";
        C_count1 = "10";
        C_canout = "UNO,无";
        C_fields = "UNO,+4";
        C_content  = "万能+4";
    }
    private void alloutaddtwoUno(){
        C_type = "alloutaddtwoUno";
        C_color1 = "#";
        C_count1 = "10";
        C_canout = "UNO,无";
        C_fields = "UNO,+2";
        C_content  = "万能+2";
    }
    private void alloutchangeUno(){
        C_type = "alloutchangeUno";
        C_icon1 = icons[0];
        C_icon2 = icons[1];
        C_icon3 = icons[2];
        C_icon4 = icons[3];

        C_color2 = colors[0];
        C_color3 = colors[1];
        C_color4 = colors[2];
        C_color5 = colors[3];
        C_color1 = "#";
        C_count1 = "1";
        C_canout = "UNO,无";
        C_fields = "UNO";
        C_content  = "转色牌";
    }
    private void setjson(){
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            C_json = objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
    public String getC_icon3() {
        return C_icon3;
    }

    public void setC_icon3(String c_icon3) {
        C_icon3 = c_icon3;
    }

    public String getC_icon4() {
        return C_icon4;
    }

    public void setC_icon4(String c_icon4) {
        C_icon4 = c_icon4;
    }

    public String getC_color3() {
        return C_color3;
    }

    public void setC_color3(String c_color3) {
        C_color3 = c_color3;
    }

    public String getC_color4() {
        return C_color4;
    }

    public void setC_color4(String c_color4) {
        C_color4 = c_color4;
    }

    public String getC_color5() {
        return C_color5;
    }

    public void setC_color5(String c_color5) {
        C_color5 = c_color5;
    }

    public String getC_json() {
        return C_json;
    }

    public void setC_json(String c_json) {
        C_json = c_json;
    }

    @Override
    public String toString() {
        return C_color1+C_icon1+C_count1+"-可出:"+C_canout+"-字段"+C_fields;
    }

    public String getC_icon1() {
        return C_icon1;
    }

    public void setC_icon1(String c_icon1) {
        C_icon1 = c_icon1;
    }

    public String getC_icon2() {
        return C_icon2;
    }

    public void setC_icon2(String c_icon2) {
        C_icon2 = c_icon2;
    }

    public String getC_count1() {
        return C_count1;
    }

    public void setC_count1(String c_count1) {
        C_count1 = c_count1;
    }

    public String getC_count2() {
        return C_count2;
    }

    public void setC_count2(String c_count2) {
        C_count2 = c_count2;
    }

    public String getC_color1() {
        return C_color1;
    }

    public void setC_color1(String c_color1) {
        C_color1 = c_color1;
    }

    public String getC_color2() {
        return C_color2;
    }

    public void setC_color2(String c_color2) {
        C_color2 = c_color2;
    }

    public String getC_type() {
        return C_type;
    }

    public void setC_type(String c_type) {
        C_type = c_type;
    }

    public String getC_content() {
        return C_content;
    }

    public void setC_content(String c_content) {
        C_content = c_content;
    }

    public String getC_canout() {
        return C_canout;
    }

    public void setC_canout(String c_canout) {
        C_canout = c_canout;
    }

    public String getC_fields() {
        return C_fields;
    }

    public void setC_fields(String c_fields) {
        C_fields = c_fields;
    }
}
